<template>
  <div :id="name">
    <el-row>
      <el-col :span="8">
        <el-button @click="getAvailable" type="primary" plain>{{ label }}</el-button>
      </el-col>
      <!-- <el-col :span="4">
        <span>{{ initData[name] === 1 ? "连接成功" : "连接失败" }}</span>
      </el-col>-->
    </el-row>
  </div>
</template>
<script>
import { test } from "@/api/dataset/interface.js";
export default {
  props: {
    initData: String,
    label: String,
    name: String,
    handleSetModel: Function
  },
  methods: {
    getAvailable() {
      // console.log("getAvailable", this.initData);
      let obj = {
        ...this.initData
      }
      test(obj).then((res) => {
        let data = res.data;
        if (data.success) {
          this.$message({
            message: data.msg || "测试成功",
            type: "success"
          });
          this.handleSetModel(1, this.name);
        } else {
          this.$message({
            message: data.msg,
            type: "error"
          });
          this.handleSetModel(0, this.name);
        }
      });
    }
  },
  mounted() {
  }
};
</script>
